package com.xls.box2023.utils;

import android.content.Context;

import com.lzz.bottomencapsulation.BuildConfig;
import com.lzz.bottomencapsulation.utils.LUtils;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.commonsdk.listener.OnGetOaidListener;

/**
 * @author lhx
 * @description:
 * @date : 2024/4/12 16:36
 */
public class UMUtil {

    private static volatile UMUtil singleton = null;

    private UMUtil() {
    }

    public static UMUtil getInstance() {
        if (singleton == null) {
            synchronized (UMUtil.class) {
                if (singleton == null) {
                    singleton = new UMUtil();
                }
            }
        }
        return singleton;
    }
    public  void preInit(Context context){

        UMConfigure.setLogEnabled(BuildConfig.isDebug);

        UMConfigure.preInit(context,BuildConfig.APPKEY_YM, ChannelUtils.getChannel(context));
    }

    /**
     * 注意: 即使您已经在AndroidManifest.xml中配置过appkey和channel值，也需要在App代码中调
     * 用初始化接口（如需要使用AndroidManifest.xml中配置好的appkey和channel值，
     * UMConfigure.init调用中appkey和channel参数请置为null）。
     */
    public void init(Context context) {
        UMConfigure.init(context,BuildConfig.APPKEY_YM, ChannelUtils.getChannel(context), UMConfigure.DEVICE_TYPE_PHONE , "");
        // 自动采集选择
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
        //手动采集选择
//      MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);
        UMConfigure.getOaid(context,new OnGetOaidListener() {
            @Override
            public void onGetOaid(String oaid) {
                LUtils.e( "oaid"+oaid);
            }});
    }

    public  void onKillProcess(Context context){
        MobclickAgent.onKillProcess(context);
    }
}
